package com.fxw.mylibrary.util;

import android.content.SharedPreferences;
import android.preference.PreferenceManager;

import com.fxw.mylibrary.BaseAppContext;
/**
 * @author xianwen.fu
 * @version v1.0
 * @Title 数据保存工具类
 * @Description:
 * @date 2015-12-7 下午3:14:56
 */
public class SharedUtils {

    public static String PHONE = "phone";//电话号码
    public static String LAST_OUTTIME = "last_outtime";//最后时间
    /**是否第一进入app key*/
    public static String FIRST = "first";
    /**勿打扰key*/
    public static String BOTHER = "bother";
    /**勿打扰起始时间key*/
    public static String BOTHER_START_TIME = "bother_start_time";
    /**勿打扰结束时间key*/
    public static String BOTHER_END_TIME = "bother_end_time";
    /**勿打扰周几key 存的 json字符串*/
    public static String BOTHER_WEEK = "bother_week";
    /**宫格布局还是卡片布局*/
    public static String GRID_OR_CARD_BAR = "grid_or_card_bar";
    private static SharedPreferences sharedPreferences;

    static {
        sharedPreferences = PreferenceManager.getDefaultSharedPreferences(BaseAppContext.getInstance());
    }

    public static void put(String key, String value) {
        sharedPreferences.edit().putString(key, value).apply();
    }

    public static void put(String key, boolean value) {
        sharedPreferences.edit().putBoolean(key, value).apply();
    }

    public static void put(String key, int value) {
        sharedPreferences.edit().putInt(key, value).apply();
    }

    public static void put(String key, float value) {
        sharedPreferences.edit().putFloat(key, value).apply();
    }

    public static void put(String key, long value) {
        sharedPreferences.edit().putLong(key, value).apply();
    }

    public static String getStringValue(String key) {
        return sharedPreferences.getString(key, "");
    }

    public static int getIntValue(String key) {
        return sharedPreferences.getInt(key, 0);
    }

    public static float getFloatValue(String key) {
        return sharedPreferences.getFloat(key, 0);
    }

    public static long getLongValue(String key) {
        return sharedPreferences.getLong(key, 0);
    }

    public static boolean getBooleanValue(String key) {
        return sharedPreferences.getBoolean(key, false);
    }

    public static boolean getBooleanValue(String key, boolean defValue) {
        return sharedPreferences.getBoolean(key, defValue);
    }

    /**
     * 移除key
     *
     * @param key
     * @Description:
     */
    public static void remove(String key) {
        sharedPreferences.edit().remove(key).apply();
    }

    /**
     * 移除所有数据
     *
     * @Description:
     */
    public static void clear() {
        sharedPreferences.edit().clear().apply();
    }

}
